package com.tn.service.tallying.impl;

import com.tn.controller.alarm.common.model.rpm.mq.EventMQDTO;
import com.tn.service.tallying.TallyingService;
import com.tn.service.vehicle.IVehicleService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName TallyingServiceImpl
 * @Description TODO
 * @Author Yezhongzhu
 * @Date 2021/12/29 15:28
 * @Version v1.0
 **/
@Service
public class TallyingServiceImpl implements TallyingService {
    /**
     * 装载车理货service
     */
    private IVehicleService vehicleService;

    /**
     * 自动注入
     *
     * @param vehicleService vehicleService
     */
    @Autowired
    public void setVehicleService(IVehicleService vehicleService) {
        this.vehicleService = vehicleService;
    }

    @Override
    public void tallyingHandle(EventMQDTO eventMQDTORpmMqDTO) {
        // 根据距离判断是否理货下发
        if (CollectionUtils.isNotEmpty(eventMQDTORpmMqDTO.getObjects())
                && 2 == eventMQDTORpmMqDTO.getObjects().size()) {
            if (1 == eventMQDTORpmMqDTO.getType()) {
                vehicleService.becomeUnreachable(eventMQDTORpmMqDTO.getObjects().get(0));
            } else if (0 == eventMQDTORpmMqDTO.getType()) {
                vehicleService.becomeReachable(eventMQDTORpmMqDTO.getObjects().get(0));
            }
        }
    }
}
